{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!mkdir models\n",
    "!pip install -q numpy opencv-python matplotlib tensorflow\n",
    "\n",
    "!bash ./load_models.sh\n",
    "!wget --quiet https://upload.wikimedia.org/wikipedia/commons/9/99/JPEG_20190317_010417.jpg -O ./data/test_img.jpg"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from hand_tracker import HandTracker\n",
    "import cv2\n",
    "import matplotlib.pyplot as plt\n",
    "from matplotlib.patches import Polygon\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "palm_model_path = \"./models/palm_detection.tflite\"\n",
    "landmark_model_path = \"./models/hand_landmark.tflite\"\n",
    "anchors_path = \"./data/anchors.csv\" "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "img = cv2.imread('./data/test_img.jpg')[:,:,::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# box_shift determines \n",
    "detector = HandTracker(palm_model_path, landmark_model_path, anchors_path,\n",
    "                       box_shift=0.2, box_enlarge=1.3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "kp, box = detector(img)\n",
    "\n",
    "f,ax = plt.subplots(1,1, figsize=(10, 10))\n",
    "\n",
    "ax.imshow(img)\n",
    "\n",
    "ax.scatter(kp[:,0], kp[:,1])\n",
    "ax.add_patch(Polygon(box, color=\"#00ff00\", fill=False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
